package com.vanguard.commons.config;

import com.vanguard.webservice.WebServiceManage;
import com.vanguard.webservice.impl.WebServiceManageImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @Title: WebService配置类
 * @Description:
 * @Author: vanguard
 * @Version: 1.0
 * @Date: 2019/02/12
 */
@Configuration
public class WebServiceConfig {

    @Bean
    public ServletRegistrationBean dispatcherServlet(){
        //发布服务名称
        return new ServletRegistrationBean(new CXFServlet(),"/webservice/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus()
    {
        return  new SpringBus();
    }

    @Bean
    public WebServiceManage webServiceManage() {
        return new WebServiceManageImpl();
    }

    @Bean
    public Endpoint endpoint() {
        //绑定要发布的服务
        EndpointImpl endpoint=new EndpointImpl(springBus(), webServiceManage());
        //显示要发布的名称
        endpoint.publish("/user");
        return endpoint;
    }
}
